home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / tdsk21sr.zip / KBSEC.C < prev    next >
C/C++ Source or Header  |  1992-08-16  |  4KB  |  91 lines

  1.  
  2. /*********************************************************************
  3. *                                                                    *
  4. *  KBSEC 1.1  -  Utilidad para medir con alta precisión la velocidad *
  5. *                de transferencia de un disco virtual (en lectura).  *
  6. *                                                                    *
  7. *                (c) 1992 Ciriaco García de Celis                    *
  8. *                                                                    *
  9. *  - No debe estar instalado un programa caché; compilar en modelo   *
  10. *  de memoria LARGO con la opción «Test stack overflow» desactivada. *
  11. *                                                                    *
  12. *********************************************************************/
  13.  
  14. #include <stdio.h>
  15. #include <dos.h>
  16. #include <conio.h>
  17.  
  18. #define MAXBUF 64512L  /* 63 Kb  (no sobrepasar 64 Kb en un acceso) */
  19. #define TIEMPO 110L    /* 6 segundos * 18,2 ≈ 110 tics (error < 1%) */
  20. #define TM 18.2      /* cadencia de interrupciones del temporizador */
  21. #define HORA_BIOS MK_FP(0x40, 0x6c)    /* variable de hora del BIOS */
  22.  
  23. unsigned long ti, vueltas, far *cbios;
  24. unsigned segmento, tamsect, far *pantalla;
  25. unsigned char far *sbuffer;
  26. static unsigned tiempo;
  27. int unidad;
  28. void interrupt (*viejaIRQ0)(), interrupt nuevaIRQ0(),
  29.   prep_hw(), rest_hw();
  30.  
  31.  
  32. void main(int argc, char **argv)
  33. {
  34.   if (allocmem ((unsigned) ((MAXBUF+0x1800) >> 4), &segmento)!=-1) {
  35.     printf("\nMemoria insuficiente.\n"); exit(255); }
  36.  
  37.   sbuffer=MK_FP((segmento+0x100) & 0xff00 | 0x80, 0); /* 2Kb+n*4Kb */
  38.  
  39.   if (argc<2) { printf("\nIndique la unidad a probar.\n"); exit(1); }
  40.   unidad=(argv[1][0] | 0x20) - 'a';
  41.   if ((unidad<2) || (absread (unidad, 1, 0L, sbuffer)!=0)) {
  42.     printf ("\nIndique unidad C o superior de menos de 32 Mb.\n");
  43.     exit (2); }
  44.  
  45.   tamsect = sbuffer[11] | (sbuffer[12]<<8);
  46.   ti = (long) tamsect * ((sbuffer[0x14] << 8) | sbuffer[0x13]);
  47.   if ((ti < MAXBUF) || (ti > 33554431L)) {
  48.     printf ("\nNecesario disco de %2.0f Kb a 32 Mb\n", MAXBUF/1024.0);
  49.     exit (3); }
  50.  
  51.   textmode (C80); clrscr();
  52.   printf ("\nCalculando velocidad (espere %2.0f seg.)...", TIEMPO/TM);
  53.  
  54.   pantalla=MK_FP((peekb(0x40,0x49)==7 ? 0xB000:0xB800), 0x140);
  55.  
  56.   prep_hw(); ti=tiempo=vueltas=0;
  57.   while (ti==tiempo); /* esperar pulso del reloj */ ti+=TIEMPO;
  58.  
  59.   while (ti >= tiempo)
  60.     if (absread (unidad, MAXBUF / tamsect, 0L, sbuffer)!=0) {
  61.       rest_hw(ti-tiempo); printf ("\nError al acceder al disco.\n");
  62.       exit(254); }
  63.     else if (!(vueltas++ & 7)) *pantalla++=0xf07;  /* "imprimir" */
  64.  
  65.   rest_hw(TIEMPO); clrscr();
  66.  
  67.   printf("\nKBSEC 1.1: Velocidad de transferencia efectiva unidad %c:\
  68.     %6.0f Kb/seg.\n", unidad+'A',MAXBUF/1024.0*vueltas/(TIEMPO/TM));
  69. }
  70.  
  71.  
  72. void interrupt nuevaIRQ0 () /* rutina ejecutada cada 55 ms */
  73. {
  74.    tiempo++;                /* incrementar nuestro contador de hora */
  75.    outportb (0x20,0x20);    /* EOI al controlador de interrupciones */
  76. }
  77.  
  78. void prep_hw()
  79. {
  80.   viejaIRQ0=getvect(8);      /* preservar vector de int. periódica */
  81.   setvect (8, nuevaIRQ0);    /* instalar nueva rutina de control   */
  82.   outportb (0x21, 0xfe);     /* inhibir todas las int. salvo timer */
  83. }
  84.  
  85. void rest_hw (unsigned long tiempo_transcurrido_con_reloj_parado)
  86. {
  87.   outportb (0x21, 0);         /* autorizar todas las interrupciones */
  88.   setvect (8, viejaIRQ0);     /* restaurar vector de int. periódica */
  89.   cbios=HORA_BIOS; *cbios+=tiempo_transcurrido_con_reloj_parado;
  90. }
  91.